import os
import json


def get_json_list(dir_name):
    """获取文件下中的json文件"""
    file_list = os.listdir(dir_name)
    json_list = [f"{dir_name}/{filename}" if filename.endswith(".json") else "" for filename in file_list]
    json_list = list(set(json_list))
    if "" not in json_list:
        return json_list
    else:
        json_list.remove("")
        return json_list


def merge_json(json_list):
    """合并json文件数据"""
    dic_list = []
    for filename in json_list:
        with open(filename, 'rb') as f:
            for row in f.readlines():
                dic_list.append(json.loads(row))
    return dic_list


if __name__ == '__main__':
    the_json_list = get_json_list(f"{os.getcwd()}/../static/data/output/countByCollege/")
    print(merge_json(the_json_list))
